using System.Collections.Generic;
using Kotonoha.Server.Core.Utils;
using Kotonoha.Server.Objects.Model;
using NHibernate;
using System.Linq;

namespace Kotonoha.Objects {
    public class WordHolder : PersistentObjectHolder<Word> {
        protected override ISession CreateSession() {
            return HibernateUtil.Model.Session;
        }

        protected override IEnumerable<Word> EnumerateItems() {
            return session.CreateQuery("from Word w left join fetch w.LearningData").List<Word>();
        }

        public bool ExistWithWriting(Word w) {
            return Collection.Count(w1 => w1.Writing.Equals(w.Writing) && w1.Reading.Equals(w.Reading)) != 0;
        }
    }
}